﻿<!DOCTYPE html>

<html lang="zh-cn">

<head>
    <meta charset="utf-8">
    <title>Stroke</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <script src="../assets/js/three.js"></script>
    <script src="../assets/js/controls/OrbitControls.js"></script>
    <script src="../assets/js/shaders/CopyShader.js"></script>
    <script src="../assets/js/postprocessing/EffectComposer.js"></script>
    <script src="../assets/js/postprocessing/RenderPass.js"></script>
    <script src="../assets/js/postprocessing/ShaderPass.js"></script>
    <script src="../assets/js/postprocessing/OutlinePass.js"></script>
    <script>
        var scene = new THREE.Scene();
        var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);

        var renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);

        var controls = new THREE.OrbitControls(camera, renderer.domElement);

        var amlight = new THREE.AmbientLight(0xffffff, 0.3);
        scene.add(amlight);

        var dirlight = new THREE.DirectionalLight(0xffffff, 0.7);
        dirlight.position.set(1, 1, 1);
        scene.add(dirlight);

        var geometry = new THREE.BoxGeometry(1, 1, 1);
        var material = new THREE.MeshPhongMaterial({ color: 0x00ff00 });
        var cube = new THREE.Mesh(geometry, material);
        scene.add(cube);

        camera.position.z = 5;

        var composer = new THREE.EffectComposer(renderer);

        var renderPass = new THREE.RenderPass(scene, camera);
        renderPass.clear = true;
        renderPass.renderToScreen = false;
        composer.addPass(renderPass);

        var outlinePass = new THREE.OutlinePass(new THREE.Vector2(renderer.domElement.width, renderer.domElement.height), scene, camera, [cube]);
        outlinePass.edgeStrength = 10;
        outlinePass.edgeGlow = 0.4;
        outlinePass.edgeThickness = 1.8;
        outlinePass.pulsePeriod = 2;
        outlinePass.visibleEdgeColor.set('#ffffff');
        outlinePass.hiddenEdgeColor.set('#190a05');
        outlinePass.clear = false;
        outlinePass.renderToScreen = true;
        composer.addPass(outlinePass);

        var animate = function () {
            requestAnimationFrame(animate);

            cube.rotation.x += 0.01;
            cube.rotation.y += 0.01;

            composer.render();
        };

        animate();
    </script>
</body>

</html>